﻿using System;
using System.Collections.Generic;
using Medianamik.Core;
using Medianamik.UI.Web.ModalWindows.ContentManagement;
using Medianamik.UI.Web.TypeList.Data;

namespace Medianamik.UI.Web.TypeList
{
    public partial class TypeSelector : TypeSelectorWindow
    {
        protected override IList<NodeType> GetLegitimateChildTypes()
        {
            return Utilities.GetListableTypes();
        }

        private bool _hasReadQueryString;
        private Guid? _currentTypeId;
        private Guid? CurrentTypeId
        {
            get
            {
                if (!_hasReadQueryString)
                    _currentTypeId = GetCurrentTypeId();
                return _currentTypeId;
            }
        }
        private Guid? GetCurrentTypeId()
        {
            _hasReadQueryString = true;
            return GetQueryStringValue<Guid?>(DefaultParamNames.TypeID).ValidateGuid();
        }

        protected override bool AddDefaultValue
        {
            get { return CurrentTypeId != null ? false : base.AddDefaultValue; }
        }

        protected override string SelectedValue
        {
            get { return CurrentTypeId != null ? CurrentTypeId.ToString() : base.SelectedValue; }
        }
    }
}
